package com.ytjj.qmyx.admin.controller.supplyChain;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.admin.config.SupplyApiConfig;
import com.ytjj.qmyx.admin.model.Admin;
import com.ytjj.qmyx.admin.model.request.SupplyChainBrandRequest;
import com.ytjj.qmyx.admin.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 供应链商品品牌
 */
@RestController
@RequestMapping("/supplyChainBrand")
@Slf4j
public class SupplyChainBrandController {

    @Autowired
    private SupplyApiConfig supplyApiConfig;


    /**
     * 查询供应链商品品牌
     *
     * @return
     */
    @PostMapping("/list")
    public String list(@RequestBody SupplyChainBrandRequest request) {
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/supplyChainBrand/list",
                JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
        return s;
    }

    /**
     * 查询供应链商品品牌
     *
     * @return
     */
    @GetMapping("/all")
    public String all(@RequestParam(required = false) String chineseName) {
        Map<String,String> map = new HashMap<>();
        map.put("chineseName",chineseName);
        String s = HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/supplyChainBrand/all", map, supplyApiConfig.getHeadsMap());
        return s;
    }

    /**
     * 新增或修改
     *
     * @return
     */
    @PostMapping("/addAndUpdate")
    public String addAndUpdate(@RequestBody SupplyChainBrandRequest request) {
        Admin admin = UserUtil.getAdmin();
        request.setOperationName(admin.getCompellation());
        request.setCreateTime(new Date());
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/supplyChainBrand/addAndUpdate", JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
        return s;
    }

    /**
     * 删除
     *
     * @return
     */
    @PostMapping("/delete")
    public String delete(@RequestBody SupplyChainBrandRequest request) {
        String s = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/supplyChainBrand/delete", JSONObject.toJSONString(request), supplyApiConfig.getHeadsMap());
        return s;
    }
}
